<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class OAPositionMapping extends Model
{
    protected $table = 'position_mapping';

    public static function getPositionMapping($roleid)
    {
        $list =  self::query()
            ->when($roleid,function ($q) use ($roleid){
                if(is_array($roleid)){
                    return $q->whereIn('roleid', $roleid)->orWhereIn('mapid', $roleid);
                }else{
                    return $q->where('roleid', $roleid)->orWhere('mapid', $roleid);
                }
            })
            ->select('roleid', 'mapid')
            ->get()
            ->toArray();
        if(empty($list)) return [$roleid];
        $arr = [];
        foreach($list as $k=>$v){
            $arr[] = $v['roleid'];
            $arr[] = $v['mapid'];
        }
        if(is_array($roleid)){
            $arr = array_merge($arr,$roleid);
        }else{
            $arr[] = $roleid;
        }
        $list = array_filter(array_unique($arr));
        return array_values($list);
    }

}
